/*
 * @Author: your name
 * @Date: 2021-06-22 21:57:36
 * @LastEditTime: 2021-06-22 22:04:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \oop1\DataStructure\LinkList\DP\dp.cpp
 */
#include <iostream>
#include <math.h>
#include <vector>
#include<string>
#include <algorithm>
#include <strstream>
#include <sstream>
using namespace std;
class Solution {
public: 

   
    int coinChangeWithMem(vector<int>& coins, int amount,vector<int>&mem)
    {
        
        if(mem[amount]!=INT_MAX)
        return mem[amount];
        if(amount==0)return 0;
        if(amount<0) return -1;

        vector<int> result ;
        int res;

        for(auto ite =coins.begin();ite!=coins.end();++ite)
        {
            res =coinChangeWithMem(coins,amount-*ite,mem);
            if(res!=-1)
            {
                result.push_back(res+1);
    
        }
        }
        
        if(result.size()!=0)
        {
            int min =result[0];
            for (auto ite=result.begin();ite!=result.end();++ite)
            {
                if(min>*ite)
                min=*ite;
            }
        mem[amount]=min;
            return min ;  
        }
        else 
        return -1;
    }
    int coinChange(vector<int>& coins, int amount) {
    vector <int> mem(amount+1,INT_MAX);
    return coinChangeWithMem(coins,amount,mem);

    }

};

void trimLeftTrailingSpaces(string &input) {
    input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
        return !isspace(ch);
    }));
}

void trimRightTrailingSpaces(string &input) {
    input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
        return !isspace(ch);
    }).base(), input.end());
}

vector<int> stringToIntegerVector(string input) {
    vector<int> output;
    trimLeftTrailingSpaces(input);
    trimRightTrailingSpaces(input);
    input = input.substr(1, input.length() - 2);
    stringstream ss;
    ss.str(input);
    string item;
    char delim = ',';
    while (getline(ss, item, delim)) {
        output.push_back(stoi(item));
    }
    return output;
}

int stringToInteger(string input) {
    return stoi(input);
}

int main() {
    string line="186,419,83,408";
    while (getline(cin, line)) {
        vector<int> coins = stringToIntegerVector(line);
        getline(cin, line);
        int amount = stringToInteger(line);
        
        int ret = Solution().coinChange(coins, amount);

        string out = to_string(ret);
        cout << out << endl;
    }
    return 0;
}